$(document).ready(initWeb);
function initWeb() {
	$("#nickname").blur(checknickname);
	$("#age").blur(checkage);
	$("#s1").blur(checkprovince);
	$("#s2").blur(checkcity);
	$("#email").blur(checkemail);
	$("#description").keyup(checkdescription);
	$("#born").blur(checkborn);
	$("#height").blur(checkheight);
	$("#weight").blur(checkweight);
	$("#school").blur(checkshcool);
	$("#occupation").blur(checkoccupation);
	$("#phone").blur(checkphone);
	$("#submit3").click(submitC);
	$("#goback").click(function(){window.location.href="index.jsp";});
//	$("#password").click(checkoldpwd);
//	$("#newpwd").click(checknewpwd);
//	$("#renewpwd").click(checkrenewpwd);
	setup();
	$(".tips").hide();
	
	 var pname = $("#pagename").val();
	 if ("1" == pname) {
	 	selectTag("tagContent1",document.getElementById("tags").getElementsByTagName("li")[1].getElementsByTagName("a")[0]);
	 } else if ("2" == pname) {
	 	selectTag("tagContent1",document.getElementById("tags").getElementsByTagName("li")[2].getElementsByTagName("a")[0]);
	 }

	var pro1 = $("#ss1").val();
	$("#s1").val(pro1);
	change(1);

	var city1 = $("#ss2").val();
	$("#s2").val(city1);

	var animal1 = $("#animal2").val();
	$("#animal").val(animal1);

	var constellation1 = $("#constellation2").val();
	$("#constellation").val(constellation1);

	var bloodtype1 = $("#bloodtype2").val();
	$("#bloodtype").val(bloodtype1);
	var education1 = $("#education2").val();
	$("#education").val(education1);
	
	setupDate();
}
function setupDate() {
   $('#born').datepicker({   
		closeText: "关闭",
		prevText: "&#x3c;上月",
		nextText: "下月&#x3e;",
		currentText: "今天",
		monthNames: ["一月","二月","三月","四月","五月","六月",
		"七月","八月","九月","十月","十一月","十二月"],
		monthNamesShort: ["一","二","三","四","五","六",
		"七","八","九","十","十一","十二"],
		dayNames: ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
		dayNamesShort: ["周日","周一","周二","周三","周四","周五","周六"],
		dayNamesMin: ["日","一","二","三","四","五","六"],
		weekHeader: "周",
		dateFormat: "yy-mm-dd",
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: true,
		yearSuffix: "年"
   });   
}
// 基本资料提交
function submitA() {
	var b2 = checknickname();
	var b50 = checkage();
	var b51 = checkprovince();
	var b52 = checkcity();
	var b6 = checkemail();
	var b7 = checkdescription();
	return (b2 && b50 && b51 && b52 && b6 && b7);
}
// 详细资料提交
function submitB() {
	var b2 = checkborn();
	var b50 = checkheight();
	var b51 = checkweight();
	var b52 = checkshcool();
	var b6 = checkoccupation();
	var b7 = checkphone();
	return (b2 && b50 && b51 && b52 && b6 && b7);
}
//密码提交
function submitC() {
	var b1 = checkoldpwd();
	var b2 = checknewpwd();
	var b3 = checkrenewpwd();
	return (b2 && b3 && b1);
}
//验证密码
function checkoldpwd() {
	var str = $("#password").val();
	if(checkmin(str, 6)) {
		showErrMsg("password", "密码长度不能小于6个字符");
		return false;
	}
	if(checkmax(str, 32)) {
		showErrMsg("password", "密码长度不能超过32个字符");
		return false;
	}
	if(!checklandn(str)) {
		showErrMsg("password", "密码只能包含字母和数字");
		return false;
	}
	hiddMsg("password");
	return true;
}
function checknewpwd() {
	var str = $("#newpwd").val();
	if(checkmin(str, 6)) {
		showErrMsg("newpwd", "密码长度不能小于6个字符");
		return false;
	}
	if(checkmax(str, 32)) {
		showErrMsg("newpwd", "密码长度不能超过32个字符");
		return false;
	}
	if(!checklandn(str)) {
		showErrMsg("newpwd", "密码只能包含字母和数字");
		return false;
	}
	hiddMsg("newpwd");
	return true;
}
//新密码
function checkrenewpwd() {
	var str = $("#renewpwd").val();
	var password = $("#newpwd").val();
	if(password != str) {
		showErrMsg("renewpwd", "两次密码不一致");
		return false;
	}
	hiddMsg("renewpwd");
	return true;
}
function selectTag(showContent, selfObj) {
	// 操作标签
	var tag = document.getElementById("tags").getElementsByTagName("li");
	var taglength = tag.length;
	for (i = 0; i < taglength; i++) {
		tag[i].className = "";
	}
	selfObj.parentNode.className = "selectTag";
	// 操作内容
	for (i = 0; j = document.getElementById("tagContent" + i); i++) {
		j.style.display = "none";
	}
	document.getElementById(showContent).style.display = "block";
}
function getPostURL() {
	return "./PhotoUploadPo";
}

function getPath(obj) {
	if (obj) {
		if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
			obj.select();
			return document.selection.createRange().text;
		} else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
			if (obj.files) {
				return obj.files.item(0).getAsDataURL();
			}
			return obj.value;
		}
		return obj.value;
	}
}
